package com.abcdefg.springmvcdemo.demo;

import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/cookie")
@RestController
public class CookieDemo {
    @RequestMapping("/r1")
    public String r1(HttpServletRequest request){
        Cookie[] cookies=request.getCookies();
        if(cookies!=null){
            for(Cookie cookie:cookies){
                System.out.println(cookie.getName()+":"+cookie.getValue());
            }
        }
        return "返回cookies成功";
    }
    @RequestMapping("/r2")
    public String r2(@CookieValue("Cookie_2") String name){
        return "Cookie_2:"+name;
    }
}
